﻿using System;

namespace Validity.Rules.Decorators
{
  public class CustomComparisonRuleDecorator<TObject, TValue>
    : ComparisonRuleDecorator<TObject, TValue>
    where TValue : IComparable
  {
    private readonly Comparison<TValue> _comparer;

    public CustomComparisonRuleDecorator(IComparisonRule<TObject, TValue> rule, Comparison<TValue> comparer)
      : base(rule)
    {
      Verify.NotNull(comparer);

      _comparer = comparer;
    }
    
    public override Boolean IsViolatedBy(TObject obj, TValue value)
    {
      return IsViolatedBy(obj, value, _comparer);
    }
  }
}
